$(function () {
    var dateTree=[
        {
            text: 'Item1',
            state: 'closed',
            children: [{
                text: 'Item11'
            },{
                text: 'Item12'
            }]
        },{
            text: 'Item2'
        }
    ]

    var $liTab=$(".liTab")

    $liTab.on("click",function () {
        $(".liTab").removeClass("just");
         $(this).addClass("just");
        var url=$(this).find("input[name='url']").val();
        $("#right").find("iframe").attr("src",url);
    }).on("mouseover",function () {
        $(this).addClass("hove");
    }).on("mouseout",function () {
        $(this).removeClass("hove");
    })
    initMenuTree();


    //初始化树形结构
    function initMenuTree() {
        $.ajax({
            url: 'menu/listMenu',
            method: "POST",
            success: function (data1) {
                var data=data1.list;
                console.log(data1);
                var username=data1.username;
                $("#username").html(username);
                $.each(data, function (i, n) {//加载父类节点即一级菜单
                    var id = n.id;
                    $('#layout_accordion').accordion('add', {
                        title: n.menuName,
                        iconCls: 'icon-users',
                        selected: false,
                        content: "<ul id='tree" + n.id + "' style='padding: 5px;font-size: 15px'></ul>",
                    });
                    $.post('menu/treeList?id=' + id,
                        function (data) {
                            $("#tree" + id).tree({
                                data: data,
                                onClick: function (node) {
                                    $(this).tree('toggle', node.target);
                                    addPanel(node.text,node.attributes[0].url);
                                }
                            });
                        }, 'json');
                });

            }
        })
    }

    var index = 0;
    function addPanel(value,value1) {
        if(!$("#tabs").tabs('exists',value)){
            index++;
            $('#tabs').tabs('add', {
                title:value,
                tabPosition:'left',
                closable: true,
                tabWidth:100,
                pill:true,
                scrollDuration:10,
                href:value1
            });
        }else{
            $('#tabs').tabs('select', value);
        }
     }
      /* function removePanel() {
         var tab = $('#tabs').tabs('getSelected');
            if (tab) {
                 var index = $('#tabs').tabs('getTabIndex', tab);
                 $('#tabs').tabs('close', index);
         }
       }*/





})
